﻿@*@model FreightSoft.Models.SHIPMENTSCHEDULE*@
@model IEnumerable<FreightSoft.Models.SHIPMENT>

@{
    ViewBag.Title = "Schedule Details";
    
}
@{
    FreightSoft.Models.Entities db = new FreightSoft.Models.Entities();
    FreightSoft.Models.SHIPMENTSCHEDULE schedule = db.SHIPMENTSCHEDULEs.Find(ViewBag.SCHEDULEID);
    //IEnumerable<FreightSoft.Models.SHIPMENT> shipments = db.SHIPMENTs.Find(ViewBag.SCHEDULEID);
}

<h2>Shipment Schedule - @schedule.SCHEDULEID</h2>
<br />
<p style="float:left">
    @if ((schedule.STATUS.Equals("Planned")) || (schedule.STATUS.Equals("Docked")))
    {
    <a href="../AutomaticAdd/@schedule.SCHEDULEID"><button type="button" class="btn btn-default" align="left">Add Shipments Automatically</button></a>
    }</p>
<p style="float:right">
    
    @if (schedule.STATUS.Equals("Released"))
    { 
        <a href="../Plan/@schedule.SCHEDULEID"><button type="button" class="btn btn-primary" style="width: 100px">Plan</button></a>
    }
     
    @if (schedule.STATUS.Equals("Planned") || schedule.STATUS.Equals("Docked"))
    {
        if (Model != null)
        {
            if (Model.Count() > 0)
            {
            <a href="../Release/@schedule.SCHEDULEID">
                <button type="button" class="btn btn-success" style="width: 100px">Release</button></a>
            }
        }
    }

    @if (schedule.STATUS.Equals("Planned") || schedule.STATUS.Equals("Released") || schedule.STATUS.Equals("Authorized"))
    {
            <a href="../Cancel/@schedule.SCHEDULEID"><button type="button" class="btn btn-info" style="width: 100px">Cancel</button></a>
    }

    @if (schedule.STATUS.Equals("Cancelled"))
    {
        <a href="../Plan/@schedule.SCHEDULEID"><button type="button" class="btn btn-info" style="width: 100px">Re-Open</button></a>
    }

    @if (schedule.STATUS.Equals("Released"))
    {
        if (User.IsInRole("SHIPAUTH") || User.IsInRole("ORDAUTH"))
        {
        <a href="../Docked/@schedule.SCHEDULEID">
            <button type="button" class="btn btn-warning" style="width: 100px">Dock</button></a> 
        }
    }

    @if (schedule.STATUS.Equals("Docked") || schedule.STATUS.Equals("Released"))
    {
        if (User.IsInRole("SHIPAUTH") || User.IsInRole("ORDAUTH"))
        {
            <a href="../Complete/@schedule.SCHEDULEID"><button type="button" class="btn btn-warning">Complete</button></a>
        }
    }


    

</p>



<table class="table">
    <tr>
        <td colspan="4">
            @if (TempData["error"] != null)
            {
                <div class="alert alert-danger">@TempData["error"]</div>
            }
        </td>
    </tr>
    <tr class="active"><td><b>Schedule Id</b></td><td><b>Planned Start Date</b></td><td><b>Planned End Date</b></td></tr>
    <tr class="active"><td>@schedule.SCHEDULEID</td><td>@schedule.PLANNED_START_DATE</td><td>@schedule.PLANNED_END_DATE</td></tr>
    <tr class="active"><td><b>Starting Port</b></td><td><b>Final Port</b></td><td><b>Status</b></td></tr>
    <tr class="active"><td>@ViewBag.ORIGINPORT </td><td>@ViewBag.DESTINATIONPORT</td><td>@schedule.STATUS</td></tr>
    <tr class="active"><td><b>Route</b></td><td><b>Maximum Volume (m3)</b></td><td><b>Maximum Weight (tons)</b></td></tr>
    <tr class="active"><td>@schedule.ROUTEID </td><td>@schedule.SHIP.TOTALVOLUME</td><td>@schedule.SHIP.TOTALWEIGHT</td></tr>
    <tr class="active"><td></td><td></td><td></td></tr>
</table>


 @if (schedule.STATUS.Equals("Planned") || schedule.STATUS.Equals("Docked"))
 {
     @*<a href="../AddShipments?PostData1=@schedule.SCHEDULEID"><button type="button" class="btn btn-info" style="width: 150px">Add Shipments</button></a>*@
     @*<button type="button" class="btn btn-primary" style="width: 100px">
         <span style="color: red;">@Html.ActionLink("Add Shipment", "AddShipments", "ShipmentSchedule", new { schedule_id =  @schedule.SCHEDULEID, route_id = @schedule.ROUTEID}, null)
             </span></button>*@
     @Html.ActionLink("Add Shipment", "AddShipments", "ShipmentSchedule", new { schedule_id = @schedule.SCHEDULEID, route_id = @schedule.ROUTEID }, null)
 }
@*<a href="../ViewShipments/@schedule.SCHEDULEID"><button type="button" class="btn btn-info" style="width: 100px">View Shipments</button></a>*@

<br />

<table class="table table-striped">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.SHIPMENTID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ORIGINPORT)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DESTINATIONPORT)
        </th>
       @* <th>
            @Html.DisplayNameFor(model => model.SCHEDULEID)
        </th>*@
        <th>
            @Html.DisplayNameFor(model => model.WEIGHT)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.VOLUME)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.STATUS)
        </th>

        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.SHIPMENTID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ORIGINPORT)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.DESTINATIONPORT)
        </td>
 @*       <td>
            @Html.DisplayFor(modelItem => item.SCHEDULEID)
        </td>*@
        <td>
            @Html.DisplayFor(modelItem => item.WEIGHT)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.VOLUME)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.STATUS)
        </td>


        <td>
           @* @Html.ActionLink("Edit", "Edit", new { id=item.SHIPMENTID }) |*@
            @Html.ActionLink("Details", "Details", "Shipment", new { id=item.SHIPMENTID }, null) | 
             @if ((schedule.STATUS.Equals("Planned") || schedule.STATUS.Equals("Docked")) || (item.STATUS.Equals("Delivered")))
 {
             @Html.ActionLink("Remove", "Remove", "Shipment", new { shipment_id=item.SHIPMENTID, schedule_id = item.SCHEDULEID }, null)
             }
            @*@Html.ActionLink("Delete", "Delete", new { id=item.SHIPMENTID })*@
        </td>
    </tr>
}

</table>

<fieldset>
   @* <legend>SHIPMENTSCHEDULE</legend>*@

   @* <div class="display-label">
         @Html.DisplayNameFor(model => model.SHIPMENTID)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.SHIPMENTID)
    </div>*@

   @* <div class="display-label">
         @Html.DisplayNameFor(model => model.ORIGINPORT)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.ORIGINPORT)
      
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.DESTINATIONPORT)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.DESTINATIONPORT)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.SHIPID)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.SHIPID)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.ROUTEID)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.ROUTEID)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.STATUS)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.STATUS)
    </div>*@

@*</fieldset>*@
<p>
   @* @Html.ActionLink("Edit", "Edit", new {Id =  Model.SCHEDULEID }) |*@
    @Html.ActionLink("Back to List", "Index") 
</p>
<p>@* 
    @Html.ActionLink("View Connected Shipments", "ViewShipments", "Shipment", new { schedule_id = Model.SCHEDULEID }, null) |
    @Html.ActionLink("Add Shipment", "AddShipment", "Shipment", new { scheduleid =  Model.SCHEDULEID, routeId = Model.ROUTEID, originPort = Model.ORIGINPORT, destinationPort = Model.DESTINATIONPORT }, null)*@

</p>
